package String;

public class _606_ConstructStringfromBinaryTree {

    /**
     *
     * @param node
     * @return
     * hint:4 case:1:t is null, return "";case 2:t is a leaf node,return t.val,case 3:t has left and right node,normal preorder traversing,
     * case 4:t has left node and don't has right node,base on the question's ask,omit the right null node ,so only return the left node
     */
    public String tree2str(TreeNode node) {
        if (node == null) {
            return "";
        }
        if (node.left == null && node.right == null) {
            return node.val+"";
        }
        if (node.right == null) {
            return node.val+"("+tree2str(node.left)+")";
        }
        return node.val+"("+tree2str(node.left)+")"+"("+tree2str(node.right)+")";
    }
}
